package cn.edu.nwpu.warehousemanagement.controller;

import cn.edu.nwpu.warehousemanagement.pojo.Result;
import cn.edu.nwpu.warehousemanagement.pojo.request.LoginRequest;
import cn.edu.nwpu.warehousemanagement.pojo.request.UpdatePWRequest;
import cn.edu.nwpu.warehousemanagement.pojo.request.UpdateSelfInfoRequest;
import cn.edu.nwpu.warehousemanagement.service.UserService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户控制类
 *
 * @author Loadstar
 * @version 1.0
 */

@RestController
@RequestMapping("/api/user")
@Validated
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/login")
    public Result<?> login(@RequestBody LoginRequest request,
                           @RequestHeader(value = "Authorization", required = false) String token) {

        return userService.login(request, token);
    }

    @PostMapping("/easyLogin")
    public Result<?> easyLogin(@RequestBody LoginRequest request,
                               @RequestHeader(value = "Authorization", required = false) String token) {

        return userService.easyLogin(request, token);
    }

    @PatchMapping("/updatepwd")
    public Result<?> updatePassword(@RequestBody UpdatePWRequest params,
                                    @RequestHeader("Authorization") String token) {
        return userService.updatePassword(params, token);

    }

    @GetMapping("/logout")
    public Result<?> logout(@RequestHeader("Authorization") String token) {
        return userService.logout(token);
    }

    @GetMapping("/getUserInfo")
    public Result<?> getUserInfo() {
        return userService.getUserInfo();
    }

    @PatchMapping("/updateUserInfo")
    public Result<?> updateUserInfo(@RequestBody @Valid UpdateSelfInfoRequest request) {
        return userService.updateUserInfo(request);
    }

    //忘记密码

    /**
     * @param forgetPWRequest 忘记密码请求
     * @return null
     * @Deprecated 忘记密码功能未实现
     */
    @PostMapping("/forgetPassword")
    public Result<?> forgetPassword(@RequestParam Object forgetPWRequest) {
//        return userService.forgetPassword(email); //todo
        return null;
    }


    @GetMapping("/hello")
    public Result<?> hello() {
        return Result.success("hello");
    }


}
